package me.ereach.exceptions;

public class Main {
    public static void main(String[] args) {
        // 1, 2, 3, 5, 8, 13, 21, 34
        System.out.println(fib(1, 2, 50));
    }

    public static long fib(long a, long b, long n) {
        long fbn = 0;

        if (n < 1)
            throw new IllegalArgumentException("输入项数必须大于0");
        else if (n == 1)
            return a;
        else if (n == 2)
            return b;

        for (int i = 2; i < n; i++) {
            fbn = a + b;
            a = b;
            b = fbn;
        }

        return fbn;
    }
}
